#include <string.h>
#include <iostream>
using namespace std;

class Computer{
public:
    Computer(const char * brand ,double price)
    :_brand( new char[strlen(brand) + 1]()), _price(price){
        cout << "Computer()" << endl;
        strcpy(_brand , brand);
    }
    Computer(const Computer &rhs):
    _brand(new char[strlen(rhs._brand)]),
    _price(rhs._price){
        stpcpy(_brand, rhs._brand);
    }
    
    void toString(){
        cout << "brand: " <<_brand << endl;cout << "price: " << _price << endl;
    }

    ~Computer(){
        if(_brand){
            delete [] _brand;
            _brand = nullptr;
        }
        cout << "析构" << endl;
    }
private:
    char * _brand;
    double _price;
};

void test0( ){
    Computer pc( " huawei" , 7000);
    Computer pc2 = pc;
    pc2.toString();
}

// 拷贝构造第二种调用时机
// 当函数的实参和形参都是对象时
// 用实参初始化形参会调用拷贝构造函数
void func1(Computer pc){

}


// 拷贝构造第三种调用时机
Computer func2(){

};

void test1(){
    func2();
}


int main(void){
    test0();
}